package com.LeeCode;

/**
 * 山脉数组的峰顶索引
 */

public class Code852 {
    public static void main(String[] args) {
        int[] arr = {0, 1, 0};
        System.out.println(new Code852().peakIndexInMountainArray(arr));
    }

    public int peakIndexInMountainArray(int[] arr) {
        int left = -1, right = arr.length - 1;
        while (left + 1 < right) {
            int mid = left + (right - left) / 2;
            if (arr[mid] > arr[mid + 1]) {
                right = mid;
            } else {
                left = mid;
            }
        }
        return right;
    }
}
